package com.usian.controller;

import com.alibaba.fastjson.JSON;
import com.usian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/test")
public class Producer {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @RequestMapping("/send")
    public String send(){
        User user = new User();
        user.setUsername("张三");
        user.setAge(18);
        ArrayList<String> list = new ArrayList<>();
        list.add("海淀上庄");
        list.add("朝阳三大");
        list.add("顺义三大");
        kafkaTemplate.send("topic", JSON.toJSONString(user));
        return "11122232";
    }
}
